package com.heima.admin.controller;

import com.heima.admin.entity.AdChannel;
import com.heima.admin.service.AdChannelService;
import com.heima.common.dtos.PageRequestDto;
import com.heima.common.dtos.PageResult;
import com.heima.common.dtos.ResponseResult;
import com.heima.common.util.BeanHelper;
import com.heima.model.admin.dtos.ChannelDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/channel")
public class AdChannelController {

    @Autowired
    private AdChannelService adChannelService;

    //分页查询频道列表
    @PostMapping("/list")
    public PageResult<AdChannel> findByPage(@RequestBody ChannelDto dto){
        return adChannelService.findByPage(dto);
    }


    //新增频道信息
    @PostMapping("/save")
    public ResponseResult saveChannel(@RequestBody ChannelDto dto){
        AdChannel adChannel = BeanHelper.copyProperties(dto, AdChannel.class);
        return adChannelService.saveChannel(adChannel);
    }

    //修改频道信息
    @PutMapping("/update")
    public ResponseResult updateChannel(@RequestBody ChannelDto dto){
        AdChannel adChannel = BeanHelper.copyProperties(dto, AdChannel.class);
        return adChannelService.updateChannel(adChannel);
    }

    //删除频道信息
    @DeleteMapping("/del/{id}")
    public ResponseResult delChannel(@PathVariable Integer id){
        return adChannelService.delChannel(id);
    }

    //查询所有频道信息
    @GetMapping("/channels")
    public ResponseResult findAll(){
        return adChannelService.findAll();
    }
}
